﻿package mortal.game.view.pack.social
{
    import Message.Public.*;
    import com.mui.controls.*;
    import extend.language.*;
    import mortal.common.net.*;
    import mortal.game.cache.*;
    import mortal.game.cache.packCache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.mount.data.*;
    import mortal.game.view.pack.data.*;
    import mortal.game.view.palyer.util.*;
    import mortal.game.view.shopMall.view.*;
    import mortal.mvc.core.*;

    public class ItemFeatureTips extends Object
    {

        public function ItemFeatureTips()
        {
            return;
        }// end function

        private static function get htmlContent() : String
        {
            return "<font color=\'#ffffff\'>" + Language.getString(30032) + "</font><font color=\'#ff3c3c\'>" + Language.getString(30033) + "<font color=\'#ffffff\'>" + Language.getString(30034) + "</font>";
        }// end function

        private static function get htmlTitle() : String
        {
            return "<font color=\'#f5ff00\'>" + Language.getString(30035) + "</font>";
        }// end function

        public static function destroyItem(param1:ItemData) : void
        {
            var closeAlert:Function;
            var itemData:* = param1;
            closeAlert = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Destroy, itemData));
                }
                return;
            }// end function
            ;
            if (!itemData)
            {
                return;
            }
            Alert.isFlowMouse = true;
            Alert.show(htmlContent, null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            return;
        }// end function

        public static function equipItem(param1:ItemData) : void
        {
            var desc:String;
            var closeAlert:Function;
            var itemData:* = param1;
            closeAlert = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.BackPack_Equip, itemData));
                }
                return;
            }// end function
            ;
            if (!itemData)
            {
                return;
            }
            Alert.isFlowMouse = true;
            if (itemData.itemInfo.type < 13)
            {
                desc = Language.getStringByParam(30081, ItemsUtil.getItemName(itemData));
            }
            else
            {
                desc = Language.getString(40300);
            }
            Alert.show(desc, null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            return;
        }// end function

        public static function mountEquipItem(param1:Object) : void
        {
            var closeAlert:Function;
            var obj:* = param1;
            closeAlert = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MountEquip, obj));
                }
                return;
            }// end function
            ;
            if (!obj)
            {
                return;
            }
            var putonitemData:* = obj.putonitemData as ItemData;
            var getoffItemData:* = obj.getoffItemData as ItemData;
            var openLevel:* = GameDefConfig.instance.getSystemOpenLevel(1);
            var roleLevel:* = Cache.instance.role.entityInfo.level;
            var mountInfo:* = Cache.instance.mount.mountData;
            if (roleLevel < openLevel)
            {
                MsgManager.showRollTipsMsg(Language.getString(35480));
                return;
            }
            if (mountInfo && mountInfo.sPublicMount && mountInfo.sPublicMount.code < putonitemData.itemInfo.level)
            {
                MsgManager.showRollTipsMsg(Language.getString(35481));
                return;
            }
            Alert.isFlowMouse = true;
            Alert.show(Language.getStringByParam(30081, ItemsUtil.getItemName(putonitemData)), null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            return;
        }// end function

        public static function petEquipItem(param1:Object) : void
        {
            var closeAlert:Function;
            var obj:* = param1;
            closeAlert = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquip, obj));
                }
                return;
            }// end function
            ;
            if (!obj)
            {
                return;
            }
            var putonitemData:* = obj.putonitemData as ItemData;
            var getoffItemData:* = obj.getoffItemData as ItemData;
            var openLevel:* = GameDefConfig.instance.getSystemOpenLevel(2);
            var roleLevel:* = Cache.instance.role.entityInfo.level;
            var mountInfo:* = Cache.instance.newPet.pet;
            if (roleLevel < openLevel)
            {
                MsgManager.showRollTipsMsg(Language.getString(35482));
                return;
            }
            if (mountInfo && mountInfo.code < putonitemData.itemInfo.level)
            {
                MsgManager.showRollTipsMsg(Language.getStringByParam(35483, putonitemData.itemInfo.level));
                return;
            }
            Alert.isFlowMouse = true;
            Alert.show(Language.getStringByParam(30081, ItemsUtil.getItemName(putonitemData)), null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            return;
        }// end function

        public static function fashionEquipItem(param1:ItemData) : void
        {
            var closeAlert:Function;
            var itemData:* = param1;
            closeAlert = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.FashionDressFashionEquip, itemData));
                }
                return;
            }// end function
            ;
            if (itemData == null)
            {
                return;
            }
            if (!FashionUtil.isEquipAvailable(itemData))
            {
                return;
            }
            Alert.isFlowMouse = true;
            Alert.show(Language.getStringByParam(30081, ItemsUtil.getItemName(itemData)), null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            return;
        }// end function

        public static function wizardEquipItem(param1:Object) : void
        {
            var closeAlert:Function;
            var obj:* = param1;
            closeAlert = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.WizardEquip, obj));
                }
                return;
            }// end function
            ;
            if (!obj)
            {
                return;
            }
            var putonitemData:* = obj.putonitemData as ItemData;
            var getoffItemData:* = obj.getoffItemData as ItemData;
            Alert.isFlowMouse = true;
            Alert.show(Language.getStringByParam(30081, ItemsUtil.getItemName(putonitemData)), null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            return;
        }// end function

        public static function openPackMoney(param1:int) : int
        {
            var _loc_4:int = 0;
            var _loc_8:CDData = null;
            var _loc_2:* = Cache.instance.pack.backPackCache;
            var _loc_3:* = _loc_2.gridVec[0].grid + _loc_2.vipDrid;
            var _loc_5:* = _loc_2.currentGrid;
            var _loc_6:* = _loc_5 - _loc_3;
            var _loc_7:* = param1 - _loc_3;
            if (_loc_6 >= _loc_2.gridVec.length)
            {
                return 0;
            }
            if (_loc_2.gridVec[_loc_6].needTime > 0)
            {
                _loc_8 = Cache.instance.cd.getCDData("lockCD", CDDataType.backPackLock) as CDData;
                if (_loc_8)
                {
                    if (_loc_6 > 0)
                    {
                        _loc_4 = Math.ceil((1 - _loc_8.usedTime / _loc_8.totalTime) * (_loc_2.gridVec[_loc_6].needMoney - _loc_2.gridVec[(_loc_6 - 1)].needMoney));
                    }
                    else
                    {
                        _loc_4 = Math.ceil((1 - _loc_8.usedTime / _loc_8.totalTime) * _loc_2.gridVec[_loc_6].needMoney);
                    }
                }
            }
            else
            {
                _loc_4 = _loc_2.gridVec[_loc_6].needMoney - _loc_2.gridVec[(_loc_6 - 1)].needMoney;
            }
            _loc_4 = _loc_4 + (_loc_2.gridVec[_loc_7].needMoney - _loc_2.gridVec[_loc_6].needMoney);
            return _loc_4;
        }// end function

        public static function openPackGrid(param1:PackObject) : void
        {
            var itemData:ItemData;
            var str:String;
            var money:int;
            var amount:int;
            var showUnLock:Function;
            var hideUnlock:Function;
            var closeAlert:Function;
            var data:* = param1;
            showUnLock = function () : void
            {
                if (itemData == PackItemData.unLockingItemData)
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PackShowUnLock, data.pos));
                }
                else
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.PackShowUnLock, data.pos));
                }
                return;
            }// end function
            ;
            hideUnlock = function () : void
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PackHideUnLock, null));
                return;
            }// end function
            ;
            closeAlert = function (param1:int) : void
            {
                var str:String;
                var index:* = param1;
                if (index == Alert.OK)
                {
                    var doOpenGrid:* = function () : void
                {
                    var _loc_1:Object = {posType:EPlayerItemPosType._EPlayerItemPosTypeBag, amount:amount, clientNeedMoney:money};
                    Dispatcher.dispatchEvent(new DataEvent(EventName.OpenGrid, _loc_1));
                    return;
                }// end function
                ;
                    str = Language.getString(35484);
                    ShopFeaturTips.showUseGlodWin("openPackGrid", money, str, null, doOpenGrid);
                    ShopFeaturTips.setIsUseGoldByType("openPackGrid", false);
                }
                else if (index == Alert.CANCEL)
                {
                }
                CallLater.addCallBack(hideUnlock);
                return;
            }// end function
            ;
            itemData = data.itemData as ItemData;
            var packCache:* = Cache.instance.pack.backPackCache;
            var gridConfigstartPos:* = packCache.gridVec[0].grid + packCache.vipDrid;
            money = openPackMoney(data.pos);
            if (itemData == PackItemData.lockItemData)
            {
                amount = data.pos - packCache.capacity;
                str = Language.getStringByParam(30038, amount - packCache.canOpenGridNum, money);
                Alert.isFlowMouse = true;
                Alert.show(str, null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            }
            else if (itemData == PackItemData.unLockingItemData)
            {
                str = Language.getStringByParam(30037, money);
                amount = packCache.currentGrid - packCache.capacity;
                Alert.isFlowMouse = true;
                Alert.show(str, null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            }
            else if (itemData == PackItemData.needMoneyItemData)
            {
                amount = data.pos - packCache.capacity;
                str = Language.getStringByParam(30038, amount - packCache.canOpenGridNum, money);
                Alert.isFlowMouse = true;
                Alert.show(str, null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            }
            CallLater.addCallBack(showUnLock);
            return;
        }// end function

        public static function openWarehouseGrid(param1:int, param2:Object) : void
        {
            var amount:int;
            var money:int;
            var closeAlert:Function;
            var showUnLock:Function;
            var hideUnlock:Function;
            var pos:* = param1;
            var data:* = param2;
            closeAlert = function (param1:int) : void
            {
                var _loc_2:Object = null;
                if (param1 == Alert.OK)
                {
                    _loc_2 = {posType:EPlayerItemPosType._EPlayerItemPosTypeWarehouse, amount:amount, clientNeedMoney:money};
                    Dispatcher.dispatchEvent(new DataEvent(EventName.OpenGrid, _loc_2));
                }
                CallLater.addCallBack(hideUnlock);
                return;
            }// end function
            ;
            showUnLock = function () : void
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WarehouseShowUnLock, data));
                return;
            }// end function
            ;
            hideUnlock = function () : void
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WarehouseHideUnLock, null));
                return;
            }// end function
            ;
            amount = pos - Cache.instance.pack.warehouseCache.capacity;
            money = Cache.instance.pack.backPackCache.gridVec[pos - 36].needMoney - (Cache.instance.pack.warehouseCache.currentGrid == 36 ? (0) : (Cache.instance.pack.backPackCache.gridVec[Cache.instance.pack.warehouseCache.currentGrid - 36 - 1].needMoney));
            Alert.show(Language.getStringByParam(30600, amount, money), null, Alert.OK | Alert.CANCEL, null, closeAlert, null, 4);
            CallLater.addCallBack(showUnLock);
            return;
        }// end function

        public static function splitTip(param1:ItemData) : void
        {
            if (!param1)
            {
                MsgManager.showRollTipsMsg(Language.getString(30022));
                return;
            }
            if (param1.serverData.itemAmount <= 1)
            {
                MsgManager.showRollTipsMsg(Language.getString(30023));
                return;
            }
            if (ItemsUtil.isTaskItem(param1))
            {
                MsgManager.showRollTipsMsg(Language.getString(30024));
                return;
            }
            SplitTipWin.instance.showWin(param1);
            return;
        }// end function

        public static function bulkUse(param1:ItemData) : void
        {
            if (!param1)
            {
                MsgManager.showRollTipsMsg(Language.getString(30028));
                return;
            }
            if (ItemsUtil.isTaskItem(param1))
            {
                MsgManager.showRollTipsMsg(Language.getString(30029));
                return;
            }
            BulkUseWin.instance.show();
            BulkUseWin.instance.itemData = param1;
            return;
        }// end function

        public static function showRenameCardUseWin(param1:ItemData) : void
        {
            ReNameCardUseWin.instance.show();
            ReNameCardUseWin.instance.itemData = param1;
            return;
        }// end function

    }
}
